#include "led_sw.h"
#include "beep.h"
#include "rf_receive.h"

bit sw;
bit SwStatus    = SW_INACTIVE;
bit SwEvent     = SW_INACTIVE;

volatile bit v_SsIn;
volatile bit v_SsOld;
volatile bit v_SsActive;


void LedSW_InitReset(void)
{
    // init for led
    LED_TRIS = 0;
    OFF_LED;

    SW_TRIS = 1;
    SW_PULLUP = 1;

    SS_TRIS = 1;
    SS_PULLUP = 0;
    v_SsIn = SS;
    GPIF = 0;
    SS_INT_ANYCHANGE = 1;
    v_SsOld = v_SsIn;
    v_SsActive = false;
}

void LedSW_UpdateStatus(void)
{
    sw = ( 0 == SW_IN )? SW_ACTIVE: SW_INACTIVE;
    if( SW_ACTIVE == (sw ^ SwStatus) )
    {
        SwEvent = SW_ACTIVE;
    }
    SwStatus = sw;
}
